package com.web_bloks.widget.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Image;
import com.web_bloks.widget.client.impl.ImgAnchorImpl;

/**
 * 
 * @author Jean-Lou Dupont
 *
 */
public class ImgAnchor extends Anchor {

	Image img = null;
	
	//Deferred Binding
	ImgAnchorImpl impl = GWT.create( ImgAnchorImpl.class );
	
	/*****************************************
	 * CONSTRUCTORS 
	 *****************************************/
	
	public ImgAnchor(Image img) {
		super();
		this.img = img;
		setup( );
	}
	
	public ImgAnchor() {
		super();
	}

	/*****************************************
	 * PRIVATE 
	 *****************************************/
	public void setImg(Image img) {
		this.img = img;
		setup();
	}
	
	protected void setup() {
		
		this.getElement().appendChild(img.getElement());
		img.setVisible(true);
		impl.setup( this );
	}
	/*****************************************
	 * API
	 *****************************************/	
	public void setImgUrl(String url) {
		if (null==this.img)
			this.img = GWT.create(Image.class);
		
		img.setUrl(url);
		setup( );
	}

}//END